package com.cote.douhahou.pretloan.msg;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.cote.douhahou.pretloan.beans.AppAkomapalendConfigCustomize;
import com.cote.douhahou.pretloan.beans.OtheAkomapalendrsInfo;
import com.cote.douhahou.pretloan.R;


public class BinAkomapalenddAccoChannelDialog extends Dialog {

    private final String mobile_akomapalend;

    private final Runnable denyRunnable_akomapalend, addAccountRunnable_akomapalend;

    private ImageView logoIv_akomapalend;
    private TextView channelTv_akomapalend, mobileTv_akomapalend;
    private View cancelBtn_akomapalend, okBtn_akomapalend;

    public BinAkomapalenddAccoChannelDialog(@NonNull Context context, String mobile, Runnable denyRunnable, Runnable addAccountRunnable) {
        super(context);
        this.mobile_akomapalend = mobile;
        this.denyRunnable_akomapalend = denyRunnable;
        this.addAccountRunnable_akomapalend = addAccountRunnable;
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_bind_channel);

        getWindow().setBackgroundDrawableResource(R.color.transparent);
        setCanceledOnTouchOutside(false);
        getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

        logoIv_akomapalend = findViewById(R.id.dbacfa_iv_logo);
        channelTv_akomapalend = findViewById(R.id.dbacfa_tv_channel);
        mobileTv_akomapalend = findViewById(R.id.dbacfa_tv_mobile);
        cancelBtn_akomapalend = findViewById(R.id.dbacfa_btn_cancel);
        okBtn_akomapalend = findViewById(R.id.dbacfa_btn_ok);

        TextView textTv = findViewById(R.id.dbacfa_tv_text);
        textTv.setText(getContext().getString(R.string.bindaccount_channel_fr_title, OtheAkomapalendrsInfo.instance().getChannel_akomapalend()));

        findViewById(R.id.dbacfa_view_out).setOnClickListener(v -> dismiss());
        findViewById(R.id.dbacfa_view_in).setOnTouchListener((v, event) -> true);

        initView_akomapalend();
    }

    @SuppressLint("SetTextI18n")
    private void initView_akomapalend(){

        String channel = OtheAkomapalendrsInfo.instance().getChannel_akomapalend();

        Bitmap logoBm = AppAkomapalendConfigCustomize.instance().getChannelLogoByValue_akomapalend(channel);
        if (logoBm!=null) logoIv_akomapalend.setImageBitmap(logoBm);

        mobileTv_akomapalend.setText(mobile_akomapalend);
        channelTv_akomapalend.setText(channel);

        cancelBtn_akomapalend.setOnClickListener(v -> {
            if (denyRunnable_akomapalend !=null) denyRunnable_akomapalend.run();
            dismiss();
        });

        okBtn_akomapalend.setOnClickListener(v -> {
            if (addAccountRunnable_akomapalend !=null) addAccountRunnable_akomapalend.run();
            dismiss();
        });

    }

}
